package com.returnsoft.softphone.dto;

import java.io.Serializable;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.TimeZone;

public class SessionDto implements Serializable{
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private Integer id;
	private Date endedAt;
	private String endedAtTempury;
	private Date startedAt;
	private SessionTypeDto sessionType;
	private String peer;
	private AgentDto agent;
	private SessionDto session;
	private CampaignDto campaign;
	private String host;
	
	
	public Integer getId() {
		return id;
	}
	public void setId(Integer id) {
		this.id = id;
	}
	public Date getEndedAt() {
		return endedAt;
	}
	public void setEndedAt(Date endedAt) {
		this.endedAt = endedAt;
	}
	
	
	public Date getStartedAt() {
		return startedAt;
	}
	public void setStartedAt(Date startedAt) {
		this.startedAt = startedAt;
	}
	public SessionTypeDto getSessionType() {
		return sessionType;
	}
	public void setSessionType(SessionTypeDto sessionType) {
		this.sessionType = sessionType;
	}
	public AgentDto getAgent() {
		return agent;
	}
	public void setAgent(AgentDto agent) {
		this.agent = agent;
	}
	public CampaignDto getCampaign() {
		return campaign;
	}
	public void setCampaign(CampaignDto campaign) {
		this.campaign = campaign;
	}
	public SessionDto getSession() {
		return session;
	}
	public void setSession(SessionDto session) {
		this.session = session;
	}

	public String getEndedAtTempury() {
		SimpleDateFormat df = new SimpleDateFormat("HH:mm:ss");
		if(startedAt!=null && endedAt==null){
			long startedAtMilis = startedAt.getTime();
			Date currentTime = new Date();
			long currentTimeMilis = currentTime.getTime();
			long tiempoMilis = currentTimeMilis - startedAtMilis;

			TimeZone tz = TimeZone.getTimeZone("UTC");
			df.setTimeZone(tz);
			String time = df.format(tiempoMilis);
			endedAtTempury = time;
			return endedAtTempury;
		}else if(startedAt!=null && endedAt!=null){
			long startedAtMilis = startedAt.getTime();
			long endedAtMilis = endedAt.getTime();
			long tiempoMilis = endedAtMilis - startedAtMilis;

			TimeZone tz = TimeZone.getTimeZone("UTC");
			df.setTimeZone(tz);
			String time = df.format(tiempoMilis);
			endedAtTempury = time;
			return endedAtTempury;
		}
		
		return endedAtTempury;
	}
	
	public String getPeer() {
		return peer;
	}
	public void setPeer(String peer) {
		this.peer = peer;
	}
	public String getHost() {
		return host;
	}
	public void setHost(String host) {
		this.host = host;
	}
	
	
	

}
